PART B:
Yacc file 
%{
#include <stdio.h>
#include <stdlib.h>
%}
%token ID NUM WHILE LE GE EQ NE OR AND IF THEN ELSE DO SWITCH CASE DEFAULT BREAK FOR
%right '='
%left AND OR
%left '<' '>' LE GE EQ NE
%left '+''-'
%left '*''/'
%right UMINUS
%left '!'
%%
S       : ST1 {printf("Input while accepted.\n");exit(0);}
        | ST2 {printf("Input if-else accepted.\n");exit(0);}
        | ST4 {printf("Input do-while accepted.\n");exit(0);}
        | ST6 {printf("Input switch-case accepted.\n");exit(0);}
        | ST7 {printf("Input For-loop accepted.\n");exit(0);}
        ;
      
ST1     :    WHILE'(' E2 ')' '{' ST '}'
ST      :     ST ST
        | E';' 
        ;
ST2     : IF '(' E2 ')' THEN ST3';' ELSE ST3';'
        | IF '(' E2 ')' THEN ST3';'
        ;
ST3  : ST2
     | E
     ;
ST4  : DO '{' ST '}' WHILE'(' E2 ')'';'; 
ST5  :     ST5 ST5
     | E';'
     ;  
ST6     :    SWITCH '(' ID ')' '{' B '}'
         ;
   
B       :    C
         |    C    D
        ;
   
C      :    C    C
        |    CASE NUM ':' E ';'
        | BREAK ';'
        ;

D      :    DEFAULT    ':' E ';' BREAK ';'
        ; 
ST7       : FOR '(' E ';' E2 ';' E ')' DEF
           ;
DEF    : '{' BODY '}'
           | E';'
           | ST7
           |
           ;
BODY  : BODY BODY
           | E ';'       
           | ST7
           |            
           ;
E        : ID '=' E
          | E '+' E
          | E '-' E
          | E '*' E
          | E '/' E
          | E '<' E
          | E '>' E
          | E LE E
          | E GE E
          | E EQ E
          | E NE E
          | E OR E
          | E AND E
          | E '+' '+'
          | E '-' '-'
          | ID 
          | NUM
          ;
E2        : E'<'E
          | E'>'E
          | E LE E
          | E GE E
          | E EQ E
          | E NE E
          | E OR E
          | E AND E
          | ID
          | NUM
          ;

%%

#include "lex.yy.c"
int yyerror(char *s)
{
    printf("error");
return 0;
}
main()
{
   printf("Enter the exp: ");
   yyparse();
}

----------------------------------------------------------
Lex file
Looping.l
alpha [A-Za-z]
digit [0-9]
%%
[ \t\n]  
for       return FOR;
switch    return SWITCH;
case return CASE;
break return BREAK;
default return DEFAULT;
do    return DO;
while    return WHILE;
if    return IF;
then    return THEN;
else    return ELSE;
{digit}+    return NUM;
{alpha}({alpha}|{digit})*    return ID;
"<="    return LE;
">="    return GE;
"=="    return EQ;
"!="    return NE;

"||"    return OR;
"&&"    return AND;
.    return yytext[0];
%%

Output:
student@admin10-OptiPlex-360:~/Desktop$ lex wh.l
student@admin10-OptiPlex-360:~/Desktop$ yacc wh.y
yacc: 2 rules never reduced
yacc: 20 shift/reduce conflicts, 1 reduce/reduce conflict.
student@admin10-OptiPlex-360:~/Desktop$ gcc y.tab.c -ll 
student@admin10-OptiPlex-360:~/Desktop$ ./a.out

Enter the exp:  for(i=0;i<n;i++)i=i+1;
Input For-loop accepted.
student@admin10-OptiPlex-360:~/Desktop$ ./a.out
Enter the exp: switch(a){case 1: a=1;    break;case 2: a=2;    break;default:a=0;break;}
Input switch-case accepted.
student@admin10-OptiPlex-360:~/Desktop$ while(a>1){b=1;}
bash: syntax error near unexpected token `{b=1'
student@admin10-OptiPlex-360:~/Desktop$ ./a.out
Enter the exp: while(a>1){b=1;}
Input while accepted.
student@admin10-OptiPlex-360:~/Desktop$ ./a.out
Enter the exp:  do{a=b+1;}while(a<10);
Input do-while accepted.
student@admin10-OptiPlex-360:~/Desktop$ ./a.out
Enter the exp:  if(a==1)  then b=1; else b=2;
Input if-else accepted.
student@admin10-OptiPlex-360:~/Desktop$ ./a.out
Enter the exp: if a=b
